package handler

import (
	"demo/api/request"
	"demo/internal/dao"
	"demo/internal/model"
	"github.com/gin-gonic/gin"
	"net/http"
)

func ListDemo(c *gin.Context) {
	list := dao.ListDemo()
	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"data": list,
		"msg":  "展示成功",
	})

}

func AddDemo(c *gin.Context) {
	var req request.AddDemoReq
	if err := c.ShouldBind(&req); err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 10000,
			"msg":  "验证失败",
			"data": err.Error(),
		})
		return
	}
	video := model.Demo{
		Name: req.Name,
		Sex:  req.Sex,
		Gift: req.Gift,
		Hour: req.Hour,
	}
	if !dao.Create(&video) {
		c.JSON(http.StatusOK, gin.H{
			"code": 10000,
			"msg":  "粉丝新增失败",
			"data": nil,
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "粉丝新增成功",
		"data": video,
	})
}
